package org.jing.ext.compress;

import org.jing.core.lang.JingException;
import org.jing.core.logger.JingLogger;
import org.jing.ext.compress.archieve.DecompressFor7z;
import org.jing.ext.compress.archieve.DecompressForZip;

import java.io.File;
import java.util.List;

/**
 * Description: 解压统筹入口 <br>
 *
 * @author bks <br>
 * @since 2023-02-23 <br>
 */
public class Decompress extends BaseDecompress {
    private static final JingLogger LOGGER = JingLogger.getLogger(Decompress.class);

    @Override
    public List<File> decompress(File srcFile, String outputDirectory) {
        FileType fileType = FileType.fromFile(srcFile);
        LOGGER.debug("compress type: {}", fileType);
        switch (fileType) {
            case SEVENZ:
                return new DecompressFor7z(this).decompress(srcFile, outputDirectory);
            case ZIP:
                return new DecompressForZip(this).decompress(srcFile, outputDirectory);
            case RAR:
            case GZ:
            case BZ2:
            case TAR:
            default:
                throw new JingException("file type {} doesn't support");
        }
    }

    @Override
    public List<File> decompressMultiple(File[] srcFiles, String outputDirectory) {
        checkMultiple(srcFiles);
        FileType fileType = FileType.fromFile(srcFiles[0]);
        LOGGER.debug("compress type: {}", fileType);
        switch (fileType) {
            case SEVENZ:
                return new DecompressFor7z(this).decompressMultiple(srcFiles, outputDirectory);
            case ZIP:
                // return new DecompressForZip(this).decompressMultiple(srcFiles, outputDirectory);
            case RAR:
            case GZ:
            case BZ2:
            case TAR:
            default:
                throw new JingException("file type {} doesn't support");
        }
    }

    public static void main(String[] args) {
        /*Decompress decompress = new Decompress();
        decompress.setDeleteSrc(false);
        decompress.setPassword("farmer");
        // decompress.decompress("temp/迅雷.7z");
        decompress.decompressMultiple(new File[]{
            new File("temp/测试文档.z01"),
            new File("temp/测试文档.zip")
        });*/

    }
}
